<template>
  <div class="account-box">
    <div class="tiao">
    </div>
    <nav>管理员登录</nav>
    <div class="form">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        label-position="left"
        class="demo-ruleForm"
      >
        <el-form-item class="item" label="用户名" prop="username">
          <el-input type="text" v-model="ruleForm.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item class="item" label="密码" prop="password">
          <el-input type="password" v-model="ruleForm.password" placeholder="请输入用密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="button" type="primary" @click="submitForm('ruleForm')">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import store from 'vuex'
export default {
  components: {
    // Form,
    // Field
  },
  props: { logOn: Boolean },
  data() {
    return {
      ruleForm: {
        username: '',
        password: ''
      },
      rules: {
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          this.$store.dispatch('user/login', {...this.ruleForm})
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm() {
      this.$refs.ruleForm.resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
// 账号容器
.account-box {
  .button {
    width: 150px;
  }
  .tiao {
    margin: 15px;
  }
  nav {
    height: 50px;
    text-align: center;
    font-size: 25px;
  }
  .form {
    margin: 20px;
  }
}
</style>
